#pragma once

#include <Winsock2.h>
#include <string>
#include <vector>
#include <list>
using namespace std;

//device base infomation
struct TABLET_DEVICEINFO
{
	unsigned int max_x;
	unsigned int max_y;
	unsigned int max_pressure;
	char		 serial_id[32];
};

//pen data struct 
struct TABLET_MESSAGE_PEN
{
	unsigned int x;
	unsigned int y;
	unsigned int pressure;
	TABLET_MESSAGE_PEN() {};
	TABLET_MESSAGE_PEN(UINT _x, UINT _y, UINT _p)
	{
		x = _x;
		y = _y;
		pressure = _p;
	}
};

//key data struct 
struct TABLET_MESSAGE_KEY
{
	DWORD			id;
	unsigned short	key;			
};

//
struct TABLET_MESSAGE_ADD
{
	TABLET_DEVICEINFO	base_info;

	TABLET_MESSAGE_ADD() {}
	TABLET_MESSAGE_ADD(TABLET_DEVICEINFO &_ti)
	{
		memcpy_s(&base_info, sizeof(TABLET_DEVICEINFO), &_ti, sizeof(TABLET_DEVICEINFO));
	}
};
#define  WM_TABLET_EVENTS				WM_USER+1001

#define TABLET_EVENT_BASE				10000
#define	TABLET_EVENT_ADD				TABLET_EVENT_BASE+1
#define TABLET_EVENT_REMOVE				TABLET_EVENT_BASE+2
#define TABLET_EVENT_PEN				TABLET_EVENT_BASE+3
#define TABLET_EVENT_KEY				TABLET_EVENT_BASE+4

struct EVENT_PACKET
{
	WPARAM type;
	LPARAM lpdata;
	EVENT_PACKET() { type = 0; lpdata = 0; };
	EVENT_PACKET(WPARAM w, LPARAM l) { type = w; lpdata = l; }
	void Free()
	{
		switch (type)
		{
		case  TABLET_EVENT_ADD:
		{
			if (((TABLET_MESSAGE_ADD*)lpdata))
			{
				delete ((TABLET_MESSAGE_ADD*)lpdata); lpdata = 0;
			}
		}
		break;
		case TABLET_EVENT_PEN:
		{
			if (((TABLET_MESSAGE_PEN*)lpdata))
			{
				delete ((TABLET_MESSAGE_PEN*)lpdata); lpdata = 0;
			}
		}
		break;
		case TABLET_EVENT_KEY:
		{
			if (((TABLET_MESSAGE_PEN*)lpdata))
			{
				delete ((TABLET_MESSAGE_PEN*)lpdata); lpdata = 0;
			}
		}
		break;
		}
	}
};

class  DeviceContext
{
public:
	DeviceContext();
	DeviceContext(SOCKET s, sockaddr_in addr, TABLET_DEVICEINFO &ti);
	~DeviceContext();
public:
	SOCKET					m_socket;
	TABLET_DEVICEINFO		m_device_info;
	HANDLE					m_recv_thread_handle;
};



